package com.stedu.service.impl;

import com.stedu.bean.Owner;
import com.stedu.exception.SteduException;
import com.stedu.mapper.OwnerMapper;
import com.stedu.service.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OwnerServiceImpl implements OwnerService {
    @Autowired
    private OwnerMapper ownerMapper;
    @Override
    public boolean insert(Owner o) throws SteduException {
        return ownerMapper.insert(o) == 1;
    }

    @Override
    public boolean delete(Integer oid) throws SteduException {
        if(ownerMapper.selectByOid(oid) == null) {
            throw new SteduException("该业主不存在，无法删除");
        }

        //TODO 判断该业主下是否有报修，有 - 不允许删除

        return ownerMapper.delete(oid) == 1;
    }

    @Override
    public boolean update(Owner o) throws SteduException {
        if(ownerMapper.selectByOid(o.getOid()) == null) {
            throw new SteduException("该部门不存在，无法修改");
        }

        return ownerMapper.update(o) == 1;
    }

    @Override
    public Owner selectByOid(Integer oid) {
        return ownerMapper.selectByOid(oid);
    }


    @Override
    public List<Owner> selectByOnameAndOphone(String oname, String ophone) {
        return ownerMapper.selectByOnameAndOphone(oname, ophone);
    }




}
